import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class mundo here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class mundo extends World
{
    public int puntos=0;
    Puntos cont = new Puntos();
    Vidas vids = new Vidas();
    int nivel = 1;
    int vidas = 3;

    /**
     * Constructor for objects of class mundo.
     * 
     */
    public mundo()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(640, 480, 1); 
        
        prepareMenu();
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepareMenu()
    {
        int pos = 150;
        setBackground("fondoMenu.png");
        
        flecha f = new flecha();
        barra b1 = new barra();
        barra b2 = new barra();
        barra b3 = new barra();
        boton bot1 = new boton("JUGAR");
        boton bot2 = new boton("SALIR");
        boton bot3 = new boton("AYUDA");
        boton bot4 = new boton("CREDITOS");
        Mono mn = new Mono();
        
        Letra let1 = new Letra('b');
        Letra let2 = new Letra('u');
        Letra let3 = new Letra('b');
        Letra let4 = new Letra('b');
        Letra let5 = new Letra('l');
        Letra let6 = new Letra('e');
        
        Letra let7 = new Letra('c');
        Letra let8 = new Letra('r');
        Letra let9 = new Letra('a');
        Letra let10 = new Letra('s');
        Letra let11 = new Letra('h');
        
        addObject(mn,343,457);
        addObject(f,324,448);

        addObject(b1,74,240);
        addObject(b2,564,240);
        addObject(b3,318,5);   
        
        addObject(bot1,175,335);
        addObject(bot2,465,335);
        addObject(bot3,230,258);
        addObject(bot4,410,257);
        
        addObject(let1,pos,55);
        addObject(let2,pos+32,85);
        addObject(let3,pos+32*2,65);
        addObject(let4,pos+32*3,75);
        addObject(let5,pos+32*4,55);
        addObject(let6,pos+32*5,80);
        addObject(let7,pos+32*7,85);
        addObject(let8,pos+32*8,95);
        addObject(let9,pos+32*9,55);
        addObject(let10,pos+32*10,65);
        addObject(let11,pos+32*11,80);
        
        b3.setRotation(90);
        
    }
    
    private void prepare()
    {
        setBackground("fondo2.png");
        flecha f = new flecha();
        barra b1 = new barra();
        barra b2 = new barra();
        top tp = new top(nivel);
        Mono mn = new Mono();
        Nube n1,n2,n3;
        n1 = new Nube();
        n2 = new Nube();
        n3 = new Nube();
        Mario mariobros = new Mario();
        
        addObject(n1,620,100);
        addObject(n2,620,200);
        addObject(n3,620,300);
        
        addObject(mariobros,520,180);
        
        addObject(mn,270,457);
        addObject(f,251,448);

        addObject(b1,50,240);
        addObject(b2,434,240);
                
        addObject(tp,240,0);    
        addObject(cont,550,400);
        addObject(vids,550,430);
    }
    
    private void prepare2()
    {
        setBackground("fondoMS.png");
        flecha f = new flecha();
        barra b1 = new barra();
        barra b2 = new barra();
        top tp = new top(nivel);
        Mono mn = new Mono();
        mslug metal = new mslug();
        
        
        addObject(mn,270,457);
        addObject(f,251,448);

        addObject(b1,50,240);
        addObject(b2,434,240);
        addObject(metal,114,395);
                
        addObject(tp,240,0);    
        addObject(cont,530,35);
        addObject(vids,530,65);
    }
    
    private void prepare3()
    {
        setBackground("fondoF.png");
        flecha f = new flecha();
        barra b1 = new barra();
        barra b2 = new barra();
        top tp = new top(nivel);
        Mono mn = new Mono();
        
        Ghost g1 = new Ghost();
        Ghost g2 = new Ghost();
        Ghost g3 = new Ghost();
        Ghost2 g2a = new Ghost2();
        Ghost2 g2b = new Ghost2();
        
        addObject(g1,500,300);
        addObject(g2,200,200);
        addObject(g3,350,100);
        addObject(g2a,20,300);
        addObject(g2b,500,100);
        
        addObject(mn,270,457);
        addObject(f,251,448);

        addObject(b1,50,240);
        addObject(b2,434,240);
        
        addObject(tp,240,0);    
        addObject(cont,530,442);
        addObject(vids,530,462);
        
    }
    
    public void aumentaPuntos()
    {
        puntos++;
        if(puntos>=10)
        {
            puntos = 0 ;
            nivel++;
            menuOpcion(0);
        }
        cont.actualizaValor(puntos);
    }
    
    public void disminuyeVidas()
    {
        vidas--;
        puntos = 0;
        if(vidas==0)
        {
            nivel=4;
            menuOpcion(0);
        }
        else
        menuOpcion(0);
        vids.actualizaValor(vidas);
        cont.actualizaValor(puntos);
    }
    
    public void eliminaObjetos()
    {
        int num,i=0;
        num = getObjects(null).size();
        Actor eli;
        while(i<num)
        {
            eli= (Actor) getObjects(null).get(0);
            removeObject(eli);
            i++;
        }
    }
        
    public void menuOpcion(int op)
    {
        switch(op)
        {
           case 0://JUGAR
                  this.eliminaObjetos();
                  switch(nivel)
                  {
                       case 1:
                        this.prepare();
                        break;
                       case 2:
                        this.prepare2();
                        break;
                       case 3:
                        this.prepare3();
                        break;
                       case 4:
                        this.eliminaObjetos();
                        setBackground("gameover.png");
                        boton bot2 = new boton("ATRAS");
                        addObject(bot2,555,20);
                        nivel=1;
                        break;
                  }
                  break;
           case 1://AYUDA
                  this.eliminaObjetos();
                  setBackground("ayuda.png");
                  boton bot = new boton("ATRAS");
                  addObject(bot,555,20);
                  break;
           case 2://CREDITOS
                  this.eliminaObjetos();
                  setBackground("creditos.png");
                  boton bot2 = new boton("ATRAS");
                  addObject(bot2,555,20);
                  break;
           case 3://MENU
                  break;
           case 4://MENU
                  this.eliminaObjetos();
                  prepareMenu();
                  break;
                    
        }
    }
    
    public int getNivel()
    {
        return(nivel);
    }
}
